<?php
/*
*后台属性展示
*/
namespace app\admin\controller;
use think\Controller;
use think\Request;
use \think\Db;
class Attribute extends Base{
     //属性列表
     public function index(){
       $db = Db::name("attribute");
       $list = $db->select();
       $this->assign('list',$list);
        return $this->fetch();
     }
     //修改属性
     public function addattribute(){
        $db = Db::name('attribute');
        $request = Request::instance();//getid
        $getid = $request->route();
        $fids = $db->where('id',$getid['id'])->find();
        $arr = json_decode($fids['content'],true);


        $this->assign('list',$arr);
        return $this->fetch();
     }
     //修改属性
     public function upattribute(){
        $arr = $_POST['names'];
        $title = $_POST['title'];
        $remarks = $_POST['remarks'];
        foreach ($arr as $key => $v) {
            $list[] = [
              'name' =>$arr[$key],
              'title' =>$title[$key],
              'remarks' =>$remarks[$key],
            ];
        }
        $jsons = json_encode($list);
        $ok = Db::name('attribute')->where('id',$_POST['id'])->update(['content'=>$jsons,'time'=>time()]);
        if($ok){
          $this->success('操作成功');
        }else{
          $this->success('操作失败');
        }

     }

}
